﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Smartec.Accounts.Camel.AMS.Model.Facades;

namespace Smartec.Accounts.Camel.AMS.WebApp.Controllers
{
    public class ActivateController : Controller
    {
        //
        // GET: /Activate/

        public ActionResult Index(Guid? id)
        {
            if (id == null)
            {
                ViewData["Activated"] = "Invalide Link";
            }
            else
            {
                var Registered = RegisteredFacade.GetRegisteredByGuid((Guid)id);
                if (Registered != null)
                {
                    if (Registered.IsActive)
                    {
                        ViewData["Activated"] = "Already Activated";
                    }
                    else
                    {
                        Registered.IsActive = true;
                        RegisteredFacade.UpdateRegistered(Registered);
                        RegisteredFacade.Save();
                        ViewData["Activated"] = "This Account is now Active";
                    }

                }
                else
                {
                    ViewData["Activated"] = "Invalide Account";
                }
            }
            return View();
        }

    }
}
